home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu219.dms / pu219.adf / SOURCES / TG_Sources.lzh / TG_Eyes.c < prev    next >
C/C++ Source or Header  |  1991-08-06  |  20KB  |  628 lines

  1. /* ==================================================================== */
  2. /*                                                                      */
  3. /*  Programname        : TG Eyes.c (1.0b)                               */
  4. /*  Author & Copyright : Thomas Geib, 6750 Kaiserslautern               */
  5. /*  Date               : 31 July 1991                                   */
  6. /*                                                                      */
  7. /*  Please refer to the "TG Eyes.doc" file for terms of copying and     */
  8. /*  usage of this program.                                              */
  9. /*  This program is "AS IS" : no responsibility for any damage of       */
  10. /*  soft- / hardware is given.                                          */
  11. /*                                                                      */
  12. /*  I have included this source-code for programmers, who want to find  */
  13. /*  out how to do certain stuff like reading parameters (from WB and    */
  14. /*  CLI), how to do graphics with tmp-rastports, rastports and clipping */
  15. /*  into the workbenchscreen. I have learned from other people's source */
  16. /*  code as well.                                                       */
  17. /*                                                                      */
  18. /*  If you want to use this source-code for your own version of         */
  19. /*  "TG Eyes", you need to contact me !!! ( see TG Eyes.doc file )      */
  20. /*                                                                      */
  21. /*  For compilation (Aztec 5.0) + linking:  see makefile                */
  22. /*                                                                      */
  23. /*                                                                      */
  24. /* Have fun ...                                                         */
  25. /*                           Tom                                        */
  26. /*                                                                      */
  27. /* ==================================================================== */
  28.  
  29. #define DEFAULT_WIDTH     196
  30. #define DEFAULT_HEIGHT     72
  31. #define DEFAULT_X          60
  32. #define DEFAULT_Y          18
  33. #define DEFAULT_MAXWIDTH  300
  34. #define DEFAULT_MAXHEIGHT 110
  35. #define DEFAULT_DELAY       5
  36. #define DEFAULT_PRIORITY  -10
  37.  
  38. #define TWO_PI 6.28318531
  39.  
  40. #define PROP_LEFT_EYE_X   550   /* according to width and height                 */
  41. #define PROP_RIGHT_EYE_X 1500
  42. #define PROP_EYE_Y       1000
  43.  
  44. #define PROP_PUPIL_X      250   /* distance middle of pupil to center of eye     */
  45. #define PROP_PUPIL_Y      500
  46.  
  47. #define PROP_INV_RIM_X    350
  48. #define PROP_INV_RIM_Y    700
  49.  
  50. #define PROP_INNER_RIM_X  400   /* distance inner rim to "      "   "   "    "   */
  51. #define PROP_INNER_RIM_Y  800
  52.  
  53. #define PROP_OUTER_RIM_X  450
  54. #define PROP_OUTER_RIM_Y  900
  55.  
  56. #define EYE_COLOR 0
  57. #define RIM_COLOR 1
  58.  
  59. #define LEFT      0
  60. #define RIGHT     1
  61.  
  62. #define ERR_NONE            0
  63. #define ERR_BITPLANE        1
  64. #define ERR_GFX             2
  65. #define ERR_INTUI           3
  66. #define ERR_WIN             4
  67. #define ERR_PLANE_0         5
  68. #define ERR_PLANE_1         6
  69. #define ERR_LITTLE_PLANE_0  7
  70. #define ERR_LITTLE_PLANE_1  8
  71.  
  72. #include <exec/types.h>
  73. #include <graphics/gfx.h>
  74. #include <graphics/view.h>
  75. #include <intuition/intuition.h>
  76. #include <math.h>
  77. #include <workbench/startup.h>
  78. #include <workbench/icon.h>
  79. #include <workbench/workbench.h>
  80.  
  81.  
  82. struct NewWindow nw =
  83. {
  84.   DEFAULT_X,DEFAULT_Y,DEFAULT_WIDTH,DEFAULT_HEIGHT,0,1,
  85.   CLOSEWINDOW | DISKREMOVED | DISKINSERTED | REFRESHWINDOW,
  86.   WINDOWSIZING | WINDOWDEPTH | WINDOWCLOSE | WINDOWDRAG | SIMPLE_REFRESH,
  87.   NULL,NULL,(UBYTE *)"TG Eyes",NULL,NULL,
  88.   100, 33, DEFAULT_MAXWIDTH, DEFAULT_MAXHEIGHT,
  89.   WBENCHSCREEN
  90. };
  91.  
  92.  
  93. struct IntuiText MenuText_Settings[13] =
  94. {
  95.   { 0,1,JAM1,10,   5,NULL,(UBYTE *)"How to set TG Eyes  parameter:             ",(struct IntuiText *)&MenuText_Settings[1] },
  96.   { 0,1,JAM1,10,  20,NULL,(UBYTE *)"PARAMETER           CLI      WORKBENCH-INFO",(struct IntuiText *)&MenuText_Settings[2] },
  97.   { 0,1,JAM1,10,  30,NULL,(UBYTE *)"---------           ---      --------------",(struct IntuiText *)&MenuText_Settings[3] },
  98.   { 0,1,JAM1,10,  40,NULL,(UBYTE *)"Left window edge    X=nr     LEFTEDGE=nr   ",(struct IntuiText *)&MenuText_Settings[4] },
  99.   { 0,1,JAM1,10,  50,NULL,(UBYTE *)"Top window edge     Y=nr     TOPEDGE=nr    ",(struct IntuiText *)&MenuText_Settings[5] },
  100.   { 0,1,JAM1,10,  60,NULL,(UBYTE *)"Window width        W=nr     WIDTH=nr      ",(struct IntuiText *)&MenuText_Settings[6] },
  101.   { 0,1,JAM1,10,  70,NULL,(UBYTE *)"Window height       H=nr     HEIGHT=nr     ",(struct IntuiText *)&MenuText_Settings[7] },
  102.   { 0,1,JAM1,10,  80,NULL,(UBYTE *)"Window max.width    MW=nr    MAXWIDTH=nr   ",(struct IntuiText *)&MenuText_Settings[8] },
  103.   { 0,1,JAM1,10,  90,NULL,(UBYTE *)"Window max.height   MH=nr    MAXHEIGHT=nr  ",(struct IntuiText *)&MenuText_Settings[9] },
  104.   { 0,1,JAM1,10, 100,NULL,(UBYTE *)"Process delay       D=nr     DELAY=nr      ",(struct IntuiText *)&MenuText_Settings[10]},
  105.   { 0,1,JAM1,10, 110,NULL,(UBYTE *)"Task priority       P=nr     PRIORITY=nr   ",(struct IntuiText *)&MenuText_Settings[11]},
  106.   { 0,1,JAM1,10, 125,NULL,(UBYTE *)"Sizing gadget hidden in lower right edge.  ",(struct IntuiText *)&MenuText_Settings[12]},
  107.   { 0,1,JAM1,10, 135,NULL,(UBYTE *)"Please refer to TG Eyes.doc for more info.",NULL }
  108. };
  109.  
  110. struct MenuItem Item_Settings =
  111. {
  112.   NULL,0,0,362,145,ITEMTEXT | ITEMENABLED | HIGHNONE,0L,
  113.   &MenuText_Settings,NULL,0,NULL,NULL
  114. };
  115.  
  116. struct Menu MySettingsMenu =
  117. { NULL,70,0,88,10,MENUENABLED,(char *)"Parameters",&Item_Settings };
  118.  
  119. struct IntuiText MenuText_Copyright[8] =
  120. {
  121.   { 0,1,JAM1,10, 5,NULL,(UBYTE *)"               TG Eyes                ",(struct IntuiText *)&MenuText_Copyright[1] },
  122.   { 0,1,JAM1,10,15,NULL,(UBYTE *)"        (c)1991  Thomas Geib          ",(struct IntuiText *)&MenuText_Copyright[2] },
  123.   { 0,1,JAM1,10,30,NULL,(UBYTE *)"This program is NOT PUBLIC DOMAIN,but ",(struct IntuiText *)&MenuText_Copyright[3] },
  124.   { 0,1,JAM1,10,40,NULL,(UBYTE *)"it may be copied under the terms given",(struct IntuiText *)&MenuText_Copyright[4] },
  125.   { 0,1,JAM1,10,50,NULL,(UBYTE *)"in the TG Eyes.doc file !             ",(struct IntuiText *)&MenuText_Copyright[5] },
  126.   { 0,1,JAM1,10,65,NULL,(UBYTE *)"No responsibility for any damage of   ",(struct IntuiText *)&MenuText_Copyright[6] },
  127.   { 0,1,JAM1,10,75,NULL,(UBYTE *)"software/hardware on the use of this  ",(struct IntuiText *)&MenuText_Copyright[7] },
  128.   { 0,1,JAM1,10,85,NULL,(UBYTE *)"program given !                       ",NULL }
  129. };
  130.  
  131. struct MenuItem Item_Copyright =
  132. {
  133.   NULL,0,0,326,95,ITEMTEXT | ITEMENABLED | HIGHNONE,0L,
  134.   &MenuText_Copyright,NULL,0,NULL,NULL
  135. };
  136.  
  137. struct Menu MyMenu =
  138. { &MySettingsMenu,10,0,40,10,MENUENABLED,(UBYTE *)"Info",&Item_Copyright };
  139.  
  140.  
  141.  
  142. struct GfxBase *GfxBase;
  143. struct IntuitionBase *IntuitionBase;
  144. struct IconBase *IconBase;
  145.  
  146. struct Window *win;                  /* window variables */
  147. struct IntuiMessage *message;
  148.  
  149. struct TmpRas tmp;                   /* temporary rastport vars */
  150. APTR   tmp_rp_plane;
  151. WORD   areabuffer[200];
  152. struct AreaInfo areaInfo;
  153.  
  154. struct RastPort rp_struct;           /* rastport for drawing */
  155. struct RastPort *rp;
  156. struct BitMap bitMap;
  157.  
  158. struct RastPort little_rp;           /* rastport for drawing pupil.       */
  159. struct BitMap   little_bm;           /* shares tmp_rp with rp for filling */
  160. int             little_width,little_height;
  161.  
  162. struct Task *mytask;
  163.  
  164. int height_nodrag,                   /* some help variables -> no stupid  */
  165.     eye_minus_pupil_y,               /* calculations on constants !       */
  166.     eye_minus_pupil_x[2],
  167.     width_noborders,
  168.  
  169.     MouseX,MouseY,NewMouseX,NewMouseY,
  170.  
  171.     eye_width,eye_height,
  172.  
  173.     pupil_radius_x,pupil_radius_y,
  174.     pupil_diameter_x,pupil_diameter_y,
  175.     pupil_x[2],pupil_y[2],
  176.  
  177.     eye_x [2],eye_y,
  178.     eye_inner_rim_x,eye_inner_rim_y,   /* radius' for drawing rims  */
  179.     eye_outer_rim_x,eye_outer_rim_y,
  180.     eye_inv_rim_x_i,eye_inv_rim_y_i;   /* same as below, but int    */
  181.  
  182. float eye_inv_rim_x,eye_inv_rim_y,SCALE_X;
  183.  
  184. int delay    = DEFAULT_DELAY;
  185.     priority = DEFAULT_PRIORITY;
  186.     old_priority;
  187.     DRAGBAR  = 11; /* we'll look at system gadgets later for real height */
  188.  
  189.  
  190. int OpenAll()
  191. {
  192.   struct Gadget *gadget;
  193.  
  194.   /* ===================== OPEN LIBRARIES =========================== */
  195.   if (! (GfxBase = OpenLibrary ("graphics.library",0L)) )
  196.     return (ERR_GFX);
  197.   if (! (IntuitionBase = OpenLibrary ("intuition.library",0L)) )
  198.     return (ERR_INTUI);
  199.   if (! (win = OpenWindow (&nw)) )
  200.     return ( ERR_WIN );
  201.  
  202.   /* =============== CREATE RASTPORT FOR DRAWING ==================== */
  203.   InitBitMap ( &bitMap ,2,win->MaxWidth,win->MaxHeight );
  204.   if (! (bitMap.Planes[0] = AllocRaster (win->MaxWidth,win->MaxHeight)))
  205.     return ( ERR_PLANE_0 );
  206.   if (! (bitMap.Planes[1] = AllocRaster (win->MaxWidth,win->MaxHeight)))
  207.     return ( ERR_PLANE_1 );
  208.   InitRastPort ( &rp_struct );
  209.   rp_struct.BitMap = &bitMap;
  210.   rp = &rp_struct;
  211.  
  212.   /* ======= CREATE TEMPORARY RASTPORT FOR FILL OPERATIONS =========== */
  213.   if (! (tmp_rp_plane = AllocRaster (win->MaxWidth,win->MaxHeight)) ) return (ERR_BITPLANE);
  214.   InitArea ( &areaInfo,areabuffer,80);
  215.   rp->AreaInfo = &areaInfo;
  216.   InitTmpRas (&tmp,tmp_rp_plane,RASSIZE (win->MaxWidth,win->MaxHeight));
  217.   rp->TmpRas = &tmp;
  218.  
  219.   /* ====== CREATE LITTLE RASTPORT FOR DRAWING SOLID ELLIPSE ========= */
  220.   little_width  = (win->MaxWidth  *  (PROP_INV_RIM_X - PROP_PUPIL_X)) >> 10;
  221.   little_height = (win->MaxHeight *  (PROP_INV_RIM_Y - PROP_PUPIL_Y)) >> 10;
  222.   little_width++; little_height++;
  223.  
  224.   InitBitMap (&little_bm,2,little_width,little_height);
  225.   if (! (little_bm.Planes[0] = AllocRaster (little_width,little_height)))
  226.     return ( ERR_LITTLE_PLANE_0 );
  227.   if (! (little_bm.Planes[1] = AllocRaster (little_width,little_height)))
  228.     return ( ERR_LITTLE_PLANE_1 );
  229.   InitRastPort ( &little_rp );
  230.   little_rp.BitMap = &little_bm;
  231.   little_rp.TmpRas = &tmp;
  232.   little_rp.AreaInfo = &areaInfo;
  233.  
  234.   SetMenuStrip (win,&MyMenu);
  235.   (win->WScreen->ViewPort.Modes & LACE) ? (SCALE_X=1.4):(SCALE_X=0.7);
  236.  
  237.   mytask = FindTask (NULL);
  238.   if (mytask) old_priority = SetTaskPri ( mytask,priority );
  239.  
  240.   /* search system gadget list for  height of dragbar */
  241.  
  242.   gadget = win->FirstGadget;
  243.   while (gadget)
  244.   {
  245.     if ( gadget->GadgetType == (SYSGADGET | WDRAGGING) )
  246.     {
  247.       DRAGBAR = gadget->Height+1;
  248.       gadget  = NULL ; /* quit */
  249.     }
  250.     else gadget = gadget->NextGadget;
  251.   }
  252.  
  253.   return ( ERR_NONE );
  254. }
  255.  
  256.  
  257. void CloseAll ( int ErrCode )
  258.  
  259. {
  260.   switch (ErrCode)
  261.   {
  262.     case ERR_NONE           : SetTaskPri (mytask,old_priority);
  263.                               ClearMenuStrip(win,&MyMenu);
  264.                               FreeRaster (little_bm.Planes[1],little_width,little_height);
  265.     case ERR_LITTLE_PLANE_1 : FreeRaster (little_bm.Planes[0],little_width,little_height);
  266.     case ERR_LITTLE_PLANE_0 : FreeRaster (tmp_rp_plane,win->MaxWidth,win->MaxHeight);
  267.     case ERR_BITPLANE       : FreeRaster (bitMap.Planes[1],win->MaxWidth,
  268.                                           win->MaxHeight);
  269.     case ERR_PLANE_1        : FreeRaster (bitMap.Planes[0],win->MaxWidth,
  270.                                           win->MaxHeight);
  271.     case ERR_PLANE_0        : CloseWindow (win);
  272.     case ERR_WIN            : CloseLibrary (IntuitionBase);
  273.     case ERR_INTUI          : CloseLibrary (GfxBase);
  274.   }
  275. }
  276.  
  277.  
  278. void DrawRims()
  279. {
  280.   int i;
  281.  
  282.   SetAPen (rp,0);
  283.   RectFill (rp,2,DRAGBAR,win->Width -3,win->Height -1);
  284.  
  285.   SetAPen (rp,RIM_COLOR);
  286.  
  287.   for (i=LEFT;i<=RIGHT;i++)
  288.   {
  289.     AreaEllipse (rp,eye_x [i],eye_y,eye_outer_rim_x,eye_outer_rim_y);
  290.     AreaEnd(rp);
  291.   }
  292.  
  293.   SetAPen (rp,EYE_COLOR);
  294.   for (i=LEFT;i<=RIGHT;i++)
  295.   {
  296.     AreaEllipse (rp,eye_x [i],eye_y,eye_inner_rim_x,eye_inner_rim_y);
  297.     AreaEnd(rp);
  298.   }
  299.  
  300.   SetAPen (&little_rp,0);
  301.   RectFill (&little_rp,0,0,little_width-1,little_height-1);
  302.  
  303.   SetAPen (&little_rp,3);
  304.   AreaEllipse ( &little_rp,pupil_radius_x,pupil_radius_y,
  305.                            pupil_radius_x,pupil_radius_y );
  306.   AreaEnd (&little_rp);
  307.  
  308.   SetWrMsk ( win->RPort,0xFF );
  309.   ClipBlit ( rp,2,DRAGBAR,win->RPort,2,DRAGBAR,
  310.              width_noborders,height_nodrag,0xC0 );
  311.  
  312.   SetWrMsk ( win->RPort,0xFE );
  313.  
  314. }
  315.  
  316.  
  317. void DrawFace()
  318.  
  319. {
  320.   eye_height = (win->Height - DRAGBAR) >> 1;
  321.   eye_width  = (win->Width) >> 1;
  322.  
  323.   /* ======= coordinates of eyes =================== */
  324.   eye_x [LEFT]  =  (PROP_LEFT_EYE_X * eye_width) >> 10;
  325.   eye_x [RIGHT] =  (PROP_RIGHT_EYE_X * eye_width) >> 10;
  326.   eye_y         =  ((PROP_EYE_Y * eye_height) >> 10) + DRAGBAR;
  327.  
  328.   /* ======= radius for drawing eye-rim ellipses ======= */
  329.   eye_inner_rim_x = (PROP_INNER_RIM_X * eye_width) >> 10;
  330.   eye_inner_rim_y = (PROP_INNER_RIM_Y * eye_height) >> 10;
  331.   eye_outer_rim_x = (PROP_OUTER_RIM_X * eye_width) >> 10;
  332.   eye_outer_rim_y = (PROP_OUTER_RIM_Y * eye_height) >> 10;
  333.  
  334.   eye_inv_rim_x   = (float)(PROP_PUPIL_X * eye_width)  / 1024.0;
  335.   eye_inv_rim_y   = (float)(PROP_PUPIL_Y * eye_height) / 1024.0;
  336.   eye_inv_rim_x_i = (int)(eye_inv_rim_x+0.5);
  337.   eye_inv_rim_y_i = (int)(eye_inv_rim_y+0.5);
  338.  
  339.   /* ======= radius and diameter for drawing pupil ellipse ========== */
  340.   pupil_radius_x = abs(((PROP_INV_RIM_X - PROP_PUPIL_X) * eye_width) >> 10);
  341.   pupil_radius_y = abs(((PROP_INV_RIM_Y - PROP_PUPIL_Y) * eye_height) >> 10);
  342.   pupil_diameter_x = (pupil_radius_x <<1) + 1;
  343.   pupil_diameter_y = (pupil_radius_y <<1) + 1;
  344.  
  345.   pupil_x [LEFT] = 0;
  346.   eye_minus_pupil_y = eye_y - pupil_radius_y;
  347.   eye_minus_pupil_x[LEFT]  = eye_x [LEFT] - pupil_radius_x;
  348.   eye_minus_pupil_x[RIGHT] = eye_x [RIGHT] - pupil_radius_x;
  349.   height_nodrag = win->Height - DRAGBAR -1; /* for clip()ing */
  350.   width_noborders = win->Width - 4;
  351.  
  352.   MouseX = MouseY = -1;
  353.  
  354.   DrawRims();
  355.  
  356. }
  357.  
  358.  
  359. void DrawPupils ()
  360.  
  361. {
  362.   float alpha;
  363.   int dx_i,dy_i,i;
  364.  
  365.   MouseX = NewMouseX;
  366.   MouseY = NewMouseY;
  367.  
  368.   if (pupil_x [LEFT])    /* clear old pupils graphic */
  369.   {
  370.     ClipBlit ( &little_rp,0,0,rp,pupil_x [LEFT],pupil_y [LEFT],
  371.                pupil_diameter_x,pupil_diameter_y,0x60);
  372.     ClipBlit ( &little_rp,0,0,rp,pupil_x [RIGHT],pupil_y [RIGHT],
  373.                pupil_diameter_x,pupil_diameter_y,0x60);
  374.   }
  375.  
  376.   dy_i = MouseY - eye_y;
  377.  
  378.   for (i=LEFT;i<=RIGHT;i++)
  379.   {
  380.     dx_i = MouseX - eye_x [i];
  381.  
  382.     alpha = atan2 ( (float)dy_i,(float)dx_i * SCALE_X );
  383.  
  384.     pupil_x [i] = (int) ( cos(alpha) * eye_inv_rim_x );
  385.     pupil_y [i] = (int) ( sin(alpha) * eye_inv_rim_y );
  386.  
  387.     if ( ( abs(dx_i) <= abs(pupil_x [i]) ) &&
  388.          ( abs(dy_i) <= abs(pupil_y [i]) ) )
  389.     {
  390.       pupil_x [i] = MouseX - pupil_radius_x;
  391.       pupil_y [i] = MouseY - pupil_radius_y;
  392.     }
  393.     else
  394.     {
  395.       pupil_x [i] = pupil_x [i] + eye_minus_pupil_x [i]; /* does not work with += */
  396.       pupil_y [i] = pupil_y [i] + eye_minus_pupil_y;   /* and I have no idea,why  */
  397.     }
  398.  
  399.     ClipBlit ( &little_rp,0,0,rp,pupil_x [i],pupil_y [i],
  400.                pupil_diameter_x,pupil_diameter_y,0x60);
  401.  
  402.   }
  403.  
  404.   ClipBlit ( rp,2,DRAGBAR,win->RPort,2,DRAGBAR,
  405.              width_noborders,height_nodrag,0xC0 );
  406. }
  407.  
  408.  
  409.  
  410. void DrawSpecial (float alpha, float beta )
  411.  
  412. {
  413.   int i;
  414.  
  415.   if (pupil_x [LEFT])    /* clear old pupils graphic */
  416.   {
  417.     ClipBlit ( &little_rp,0,0,rp,pupil_x [LEFT],pupil_y [LEFT],
  418.                pupil_diameter_x,pupil_diameter_y,0x60);
  419.     ClipBlit ( &little_rp,0,0,rp,pupil_x [RIGHT],pupil_y [RIGHT],
  420.                pupil_diameter_x,pupil_diameter_y,0x60);
  421.   }
  422.  
  423.   for (i=LEFT;i<=RIGHT;i++)
  424.   {
  425.     pupil_x [i] = (int) ( cos(alpha) * eye_inv_rim_x )
  426.                  + eye_minus_pupil_x [i];
  427.     pupil_y [i] = (int) ( sin(alpha) * eye_inv_rim_y )
  428.                  + eye_minus_pupil_y;
  429.  
  430.     ClipBlit ( &little_rp,0,0,rp,pupil_x [i],pupil_y [i],
  431.                pupil_diameter_x,pupil_diameter_y,0x60);
  432.     alpha = beta;
  433.   }
  434.  
  435.   ClipBlit ( rp,2,DRAGBAR,win->RPort,2,DRAGBAR,
  436.              width_noborders,height_nodrag,0xC0 );
  437. }
  438.  
  439.  
  440.  
  441. void Roll_Eyes ( int inserted )
  442.  
  443. {
  444.   float alpha,beta,dx,dy,gamma;
  445.  
  446.  
  447.  
  448.   dy = (float)(win->MouseY - eye_y);
  449.  
  450.   dx = (float)(win->MouseX - eye_x[0]) * SCALE_X;
  451.   alpha = atan2 ( dy,dx );
  452.  
  453.   dx = (float)(win->MouseX - eye_x[1]) * SCALE_X;
  454.   beta  = atan2 ( dy,dx );
  455.  
  456.  
  457.   if (inserted) Delay ( 50 );
  458.  
  459.   gamma = 0.0;
  460.  
  461.  
  462.   while (gamma < TWO_PI)
  463.   {
  464.     DrawSpecial (alpha,beta);
  465.     gamma += 0.15;
  466.     alpha += 0.15;
  467.     beta  -= 0.15;
  468.   }
  469.  
  470.   DrawPupils();
  471. }
  472.  
  473.  
  474. void HandleIDCMP ()
  475. {
  476.   USHORT class;
  477.  
  478.   for (;;)
  479.   {
  480.     while ( message = (struct IntuiMessage *) GetMsg (win->UserPort) )
  481.     {
  482.       class = message->Class;
  483.       ReplyMsg ((struct Message *)message);
  484.  
  485.       switch (class)
  486.       {
  487.         case CLOSEWINDOW   : return();
  488.         case REFRESHWINDOW : DrawFace();   break;
  489.         case DISKREMOVED   : Roll_Eyes(0); break;
  490.         case DISKINSERTED  : Roll_Eyes(1); break;
  491.       }
  492.  
  493.     }
  494.  
  495.     NewMouseX = win->MouseX;
  496.     NewMouseY = win->MouseY;
  497.  
  498.     if ( (NewMouseX != MouseX) || (NewMouseY != MouseY) )
  499.       DrawPupils ();
  500.  
  501.     Delay (delay);
  502.   }
  503. }
  504.  
  505.  
  506. int compare ( char *str_ptr_1, char *str_ptr_2, int length )
  507. {
  508.   APTR ptr;
  509.  
  510.   if (! (strncmp ( str_ptr_1,str_ptr_2,length )) )
  511.   {
  512.     if ((strlen (str_ptr_2)) > length)
  513.     {
  514.       ptr = (APTR) ((int)str_ptr_2 + (int)length);
  515.       return ( atoi (ptr));
  516.     }
  517.   }
  518.   return ( -1 );
  519. }
  520.  
  521.  
  522. void GetParameters ( int count, char *arg_ptr[],
  523.                      struct WBStartup *arg_wb_ptr )
  524.  
  525. {
  526.   int i,x;
  527.   struct WB_Arg *wb_args;
  528.   struct DiskObject *disk_obj;
  529.   char **toolarray;
  530.   char *s;
  531.  
  532.   if (count)
  533.   {
  534.     for (i=1;i<count;i++)
  535.     {
  536.       if ( (x = compare ("X=",arg_ptr[i],2)) != -1 )
  537.         nw.LeftEdge = x;
  538.       else
  539.       if ( (x = compare ("Y=",arg_ptr[i],2)) != -1 )
  540.         nw.TopEdge = x;
  541.       else
  542.       if ( (x = compare ("W=",arg_ptr[i],2)) != -1 )
  543.         nw.Width = x;
  544.       else
  545.       if ( (x = compare ("H=",arg_ptr[i],2)) != -1 )
  546.         nw.Height = x;
  547.       else
  548.       if ( (x = compare ("MW=",arg_ptr[i],3)) != -1 )
  549.         nw.MaxWidth = x;
  550.       else
  551.       if ( (x = compare ("MH=",arg_ptr[i],3)) != -1 )
  552.         nw.MaxHeight = x;
  553.       if ( (x = compare ("D=",arg_ptr[i],2)) != -1 )
  554.         delay = x;
  555.       else
  556.       if ( (x = compare ("P=",arg_ptr[i],2)) != -1 )
  557.         priority = x;
  558.     }
  559.   }
  560.   else
  561.   { /* started from workbench */
  562.     if ( IconBase = OpenLibrary ("icon.library",0L) )
  563.     {
  564.  
  565.       wb_args = (struct WBArg *)arg_wb_ptr->sm_ArgList;
  566.       if (*wb_args->wa_Name)
  567.       {
  568.         if (disk_obj = GetDiskObject (wb_args->wa_Name))
  569.         {
  570.           toolarray = (char **) disk_obj->do_ToolTypes;
  571.           if (s=(char *)FindToolType(toolarray,"LEFTEDGE"))
  572.             nw.LeftEdge = atoi (s);
  573.           if (s=(char *)FindToolType(toolarray,"TOPEDGE"))
  574.             nw.TopEdge = atoi (s);
  575.           if (s=(char *)FindToolType(toolarray,"WIDTH"))
  576.             nw.Width = atoi (s);
  577.           if (s=(char *)FindToolType(toolarray,"HEIGHT"))
  578.             nw.Height = atoi (s);
  579.           if (s=(char *)FindToolType(toolarray,"MAXWIDTH"))
  580.             nw.MaxWidth = atoi (s);
  581.           if (s=(char *)FindToolType(toolarray,"MAXHEIGHT"))
  582.             nw.MaxHeight = atoi (s);
  583.           if (s=(char *)FindToolType(toolarray,"DELAY"))
  584.             delay = atoi(s);
  585.           if (s=(char *)FindToolType(toolarray,"PRIORITY"))
  586.             priority = atoi (s);
  587.  
  588.           FreeDiskObject ( disk_obj );
  589.         }
  590.       }
  591.       CloseLibrary (IconBase);
  592.     }
  593.   }
  594.  
  595.   /* now check parameters */
  596.  
  597.   if ( (delay < 0) || (delay > 500) ) delay = DEFAULT_DELAY;
  598.   if ( (priority < 128) || (priority > 127) ) priority = DEFAULT_PRIORITY;
  599.  
  600.   if (nw.Width  < nw.MinWidth) nw.Width = nw.MinWidth;
  601.   if (nw.Height < nw.MinHeight) nw.Height = nw.MinHeight;
  602.   if (nw.MaxWidth < nw.Width) nw.MaxWidth = nw.Width;
  603.   if (nw.MaxHeight < nw.MaxHeight) nw.MaxHeight = nw.Height;
  604.   if (nw.LeftEdge < 0) nw.LeftEdge = 0;
  605.   if (nw.TopEdge < 0) nw.TopEdge = 0;
  606. }
  607.  
  608.  
  609.  
  610. int main ( int argc, char *argv[] )
  611.  
  612. {
  613.   int ErrCode;
  614.  
  615.   GetParameters (argc,argv,argv);
  616.  
  617.   if ( ( ErrCode = OpenAll() ) == ERR_NONE )
  618.   {
  619.     DrawFace ();
  620.     NewMouseX = win->MouseX;
  621.     NewMouseY = win->MouseY;
  622.     DrawPupils ();
  623.     HandleIDCMP ();
  624.   }
  625.   CloseAll ( ErrCode );
  626.   return (0);
  627. }
  628.